/*    This file is part of nit.
 *
 *    Nit is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU Lesser General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    Nit is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public License
 *    along with nit.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef ERR_H
#define ERR_H

#include <stdlib.h>

typedef enum {
	NIT_ERROR_FINE = 0,
	NIT_ERROR_MEMORY,
	NIT_ERROR_EMPTY,
	NIT_ERROR_NO_NEXT,
	NIT_ERROR_ALREADY,
	NIT_ERROR_NOT_FOUND,
	NIT_ERROR_NOT_DOABLE,
	NIT_ERROR_NOT_UNDOABLE,
	NIT_ERROR_NOT_DIFF,
	NIT_ERROR_FAILED,
	NIT_ERROR_ROI,
	NIT_ERROR_REDO_PAST,
} Nit_error;

typedef struct Err Err;

typedef void (*Err_log)(Err *err);

struct Err {
	Err_log log;
	const char *custom;
	int errnum;
	char *where;
	char *what;
	size_t where_len;
	size_t what_len;
	size_t under;
	size_t line;
        size_t pos;
	unsigned print_under : 1;
	unsigned print_where : 1;
	unsigned print_what : 1;
	unsigned print_line : 1;
	unsigned print_pos : 1;
	unsigned occured : 1;
};

void
err_init(Err *err, Err_log log);

void
err_dispose(Err *err);

void
err_std(Err *err);

void
err_nit(Err *err, Nit_error error);

void
err_cust(Err *err, const char *msg);

void
err_under(Err *err, size_t under);

int
err_where(Err *err, const char *where);

int
err_what(Err *err, const char *what);

void
err_line(Err *err, size_t line);

void
err_pos(Err *err, size_t pos);

void
err_log(Err *err);

#endif
